home *** CD-ROM | disk | FTP | other *** search
/ Suzy B Software 2 / Suzy B Software CD-ROM 2 (1994).iso / extras / programm / gemfsc20 / gemfsc20.lzh / GEMFUNCS / FSLDIALO.C < prev    next >
C/C++ Source or Header  |  1993-03-20  |  4KB  |  128 lines

  1. /**************************************************************************
  2.  * FSLDIALO.C - fsl_dialog(): conduct complete fsel_exinput dialog.
  3.  *
  4.  *    02/29/92 -    v1.8
  5.  *                Renamed and made this a gemfast routine.
  6.  *************************************************************************/
  7.  
  8. #include "gemfintl.h"
  9. #include <osbind.h>
  10.  
  11. #ifdef GEMFAST_PROTOS
  12.   static void build_fullname(char *outpath, char *inpath, char *force_fname)
  13. #else
  14.   static void build_fullname(outpath, inpath, force_fname)
  15.     register char *outpath;
  16.     register char *inpath;
  17.     char          *force_fname;
  18. #endif
  19. {
  20.     register char *name_node = outpath;
  21.     register char c;
  22.  
  23.     while ('\0' != (*outpath++ = (c = *inpath++))) {
  24.         if (c == '\\') {
  25.             name_node = outpath;
  26.         }
  27.     }
  28.     --outpath;
  29.  
  30.     if (*(outpath-1) == '\\') {
  31.         strcpy(outpath, "*.*");
  32.     }
  33.  
  34.     if (force_fname != NULL) {
  35.         strcpy(name_node, force_fname);
  36.     }
  37.  
  38. }
  39.  
  40. short fsl_dialog(options, pfullname, ppath, pwild, pprompt)
  41.     short              options;
  42.     char             *pfullname;
  43.     register char     *ppath;
  44.     char             *pwild;
  45.     char             *pprompt;
  46. {
  47.     short              button;
  48.     char              fpath[128];
  49.     static char      *lastpath;
  50.     static char GFAR  internal_path[128];
  51.     static char GFAR  fname[14];
  52.  
  53.     /*---------------------------------------------------------------------
  54.      * a little setup...
  55.      *-------------------------------------------------------------------*/
  56.  
  57.     if (pfullname == NULL) {        /* this parameter is not optional     */
  58.         return FALSE;                /* naughty caller...                 */
  59.     }
  60.  
  61.     if (options & FSL_PATHONLY) {      /* if the caller wants pathname only */
  62.         options |= FSL_FNOPTIONAL;      /* that implies filename optional    */
  63.     }
  64.  
  65.     /*---------------------------------------------------------------------
  66.      * If we were given a path, use it, else use the internal path buffer.
  67.      * if the path is an empty string, init it to the current dev/path.
  68.      * If the path we're using is not the same as last time we were
  69.      * called, nuke the last filename so it doesn't show in the fsel.
  70.      *-------------------------------------------------------------------*/
  71.  
  72.     if (ppath == NULL) {
  73.         ppath = internal_path;
  74.     }
  75.  
  76.     if (ppath != lastpath) {
  77.         fname[0] = '\0';
  78.     }
  79.     lastpath = ppath;
  80.  
  81.     if (*ppath == '\0') {
  82.         ppath[0] = 'A' + (short)Dgetdrv();
  83.         ppath[1] = ':';
  84.         Dgetpath(&ppath[2], 0);
  85.         strcat(ppath, "\\");
  86.     }
  87.  
  88.     build_fullname(fpath, ppath, pwild);
  89.  
  90.     /*---------------------------------------------------------------------
  91.      * if we weren't given a prompt, supply a reasonable default.
  92.      *-------------------------------------------------------------------*/
  93.  
  94.     if (pprompt == NULL) {
  95.         pprompt = (options & FSL_PATHONLY) ? "Select Path" : "Select File";
  96.     }
  97.  
  98.     /*---------------------------------------------------------------------
  99.      * do the dialog.  if the user cancelled, or if the user didn't
  100.      * select a filename when a filename is required, return FALSE;
  101.      *-------------------------------------------------------------------*/
  102.  
  103.     fsel_exinput(fpath, fname, &button, pprompt);
  104.  
  105.     if (button == 0 || (fname[0] == '\0' && !(options & FSL_FNOPTIONAL))) {
  106.         return FALSE;
  107.     }
  108.  
  109.     /*---------------------------------------------------------------------
  110.      * copy the path from the fsel to the permenant copy for next time.
  111.      * if we were only looking for a pathname, nuke any filename
  112.      * the user might have selected.  build the full name into the caller's
  113.      * return value buffer, and return TRUE.
  114.      *-------------------------------------------------------------------*/
  115.  
  116.     strcpy(ppath, fpath);
  117.  
  118.     if (options & FSL_PATHONLY) {
  119.         fname[0] = '\0';
  120.     }
  121.  
  122.     build_fullname(pfullname, fpath, fname);
  123.  
  124.     return TRUE;
  125. }
  126.  
  127.  
  128.